package com.vision.sales.sv.report;

import java.util.HashMap;
import java.util.Map;

import com.vision.sales.cm.db.data.Customer;

/**
 * 
 * @author Mark
 *
 */
public class CustomerAgingRow implements Comparable<CustomerAgingRow> {
	
	public static final String[] TERMS = { "30 Days", "60 Days", "90 Days", "150 Days or More" };
	
	private Customer customer;
	private Map<String, Double> balancesMap;
	
	public CustomerAgingRow(Customer customer, Map<String, Double> balancesMap) {
		this.customer = customer;
		this.balancesMap = balancesMap;
	}

	public Object get(String column) {
		if ("customer".equals(column))
			return customer.getName();
		
		return balancesMap.get(column);
	}
	
	public Customer getCustomer() {
		return customer;
	}
	
	public Map<String, Double> getBalancesMap() {
		if (balancesMap == null)
			balancesMap = new HashMap<String, Double>();
		return balancesMap;
	}
	
	public void computeTotal() {
		double total = 0;
		for (String month : TERMS) {
			Double value = getBalancesMap().get(month);
			if (value != null)
				total += value;
			else
				getBalancesMap().put(month, 0d);
		}
		
		getBalancesMap().put("total", total);
	}
	
	@Override
	public int compareTo(CustomerAgingRow r) {
		return getCustomer().getName().compareToIgnoreCase(r.getCustomer().getName());
	}

}
